// pages/message/message.js
import http from '../../utils/http.js';
import { noticeDetail } from '../../utils/notice.js';
const messageType = {
  'remind': '提醒',
  'info': '消息',
  'warning': '警告',
  'hotspot': '热点'
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
    msgList: [],
    topList: []
  },
  //消息跳转
  msgDetail: function (e) {
    let id = e.currentTarget.dataset.id;
    let type = e.currentTarget.dataset.type;
    let title = "";
    let content = "";
    let time = "";
    let detail = e.currentTarget.dataset;
    title = e.currentTarget.dataset.title;
    content = e.currentTarget.dataset.content;
    time = e.currentTarget.dataset.time;
    noticeDetail.setValue(detail);
    if (type === "hotspot") {
      wx.navigateTo({
        url: '../index/msgDetail/msgDetail',
      })
    } else {
      wx.showModal({
        title: title,
        content: content,
        showCancel: false,
      })
    }
  },
  // 获取消息列表
  getNotice: function () {
    http.request({
      url: '/findNotice ',
      success: (res) => {
        let topList = [];
        let msgList = [];
        for (let i = 0; i < res.length; i++) {
          if (res[i].roof === 1) {
            res[i].typeCn = messageType[res[i].type];
            topList.push(res[i]);
          } else {
            res[i].typeCn = messageType[res[i].type];
            msgList.push(res[i]);
          }
        }
        this.setData({
          topList: topList,
          msgList: msgList
        })
      },
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getNotice();
  },

})